package nxu.service;

import nxu.dao.DbHelper;
import nxu.entity.Category;

import java.util.List;

public class CategoryService {
    public List<Category> findAll(){
            String findAllCategorySql="select * from category";
            return DbHelper.JDBI.withHandle(handle -> handle.createQuery(findAllCategorySql)
                    .mapToBean(Category.class)
                    .list()
            );

    }

    public boolean addCategory(String cid,String cname){
        System.out.println(cid+cname);
        boolean success=false;
        try {
        String addSql ="insert category(cid,cname) values(:cid,:cname)";
        DbHelper.JDBI.withHandle(handle -> handle.createUpdate(addSql)
                .bind("cid",cid)
                .bind("cname",cname)
                .execute()
        );
        success=true;
        }catch (Exception e){
            System.out.println("error");
        }

        return success;
    }
}
